package tech.youai.ppping;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class PingRestController {

    private final Configuration configuration;

    @Autowired
    public PingRestController(Configuration configuration) {
        this.configuration = configuration;
    }

    @RequestMapping(value = "/ping",method = RequestMethod.GET, produces = "application/json")
    public ResponseEntity<PingResult> ping(@RequestParam(value ="url") String url) {
        PingResult r = (new UrlPing()).ping(url);
        return ResponseEntity.ok(r);
    }
    @RequestMapping(value = "/customers",method = RequestMethod.GET, produces = "application/json")
    public ResponseEntity customers() {
        Map<String, String> r = configuration.getUrlsMap();
        return ResponseEntity.ok(r);
    }
}
